package cn.bass.marketing.common.constant;

import lombok.Getter;

import java.util.Arrays;

/**
 * {@author}: LiuWei
 * {@version}: 1.0
 * {@since}: 2024-08-15
 * {@link}: cn.bass.marketing.common.constant.RulesConstant
 * 描述：权重规则枚举
 */
@Getter
public enum RulesConstant {
    RULE_BLACKLIST("黑名单权重规则","rule_blacklist"),

    RULE_WEIGHT("权重规则","rule_weight");


    private final String name;
    private final String value;

    RulesConstant(String name, String value) {
        this.name = name;
        this.value = value;
    }


    public static RulesConstant getRuleBlacklist(String value) {
        if (null == value) {
            return null;
        }
        if (value.contains(StringSignConstant.COMMA)) {
            String[] values = value.split(StringSignConstant.COMMA);
            if (Arrays.stream(values).anyMatch(item -> item.equals(RULE_BLACKLIST.getValue()))) {
                return RULE_BLACKLIST;
            }
        }
        if (value.equals(RulesConstant.RULE_WEIGHT.getValue())) {
            return RulesConstant.RULE_WEIGHT;
        }
        return null;
    }
}
